
# In[]
import numpy as np
import matplotlib.pyplot as plt

# In[]
with open("dumped_json.json","rb") as f:
    data = f.read()

data=str(data)
# In[]
fps = data.split('fps:')[2:]
for i in range(len(fps)):
    fps[i] = float(fps[i].split(',')[0])
    
plt.plot(fps)
plt.ylim(0,30)

plt.xlabel('timestamp of logfile')
plt.ylabel('fps')


fps = np.array(fps)
print('mean:', fps.mean())


# %%
avg_delay = data.split('avg_delay: ')[4:]
avg_delay = avg_delay[1::2]

for i in range(len(avg_delay)):
    avg_delay[i] = float(avg_delay[i].split(',')[0])

avg_delay = np.array(avg_delay)
print('avg mean:', avg_delay.mean())


max_delay = data.split('max_delay: ')[4:]
max_delay = max_delay[1::2]
for i in range(len(max_delay)):
    max_delay[i] = float(max_delay[i].split(',')[0])

plt.plot(avg_delay)
plt.plot(max_delay)
plt.ylim(0,50)

plt.xlabel('timestamp of logfile')
plt.ylabel('delay (ms) ')
plt.legend(['avg_delay', 'max_delay'])

max_delay = np.array(max_delay)
print('max mean:', max_delay.mean())

# %%
avg_preprocess_time = data.split('avg_preprocess_time: ')[2:]
avg_preprocess_time = avg_preprocess_time[1::2]

for i in range(len(avg_preprocess_time)):
    avg_preprocess_time[i] = float(avg_preprocess_time[i].split(',')[0])
    
plt.plot(avg_preprocess_time)
plt.ylim(0,25)

plt.xlabel('timestamp of logfile')
plt.ylabel('avg_preprocess_time')


avg_preprocess_time = np.array(avg_preprocess_time)
print('mean:', avg_preprocess_time.mean())


# %%
avg_postprocess_time = data.split('avg_postprocess_time: ')[2:]
for i in range(len(avg_postprocess_time)):
    avg_postprocess_time[i] = float(avg_postprocess_time[i].split(',')[0])
    
plt.plot(avg_postprocess_time)
plt.ylim(0,4)

plt.xlabel('timestamp of logfile')
plt.ylabel('avg_postprocess_time')


avg_postprocess_time = np.array(avg_postprocess_time)
print('mean:', avg_postprocess_time.mean())




# %%
print(len(avg_delay))
print(len(avg_preprocess_time))
print(len(avg_postprocess_time))

model_time = avg_delay[0:] - avg_preprocess_time[1:] - avg_postprocess_time[1:]

print(model_time.mean())

plt.plot(model_time)
# plt.ylim(0,2)

plt.xlabel('timestamp of logfile')
plt.ylabel('model infer time')

# %%





